Skip to content

Allow InitializeComponent to have parameters - #1632

Open
Yexuan Xiao (YexuanXiao) wants to merge 3 commits into
microsoft:masterfrom
YexuanXiao:init-with-args
Open

Yexuan Xiao (YexuanXiao) wants to merge 3 commits into
microsoft:masterfrom
YexuanXiao:init-with-args

Conversation

@YexuanXiao

@YexuanXiao Yexuan Xiao (YexuanXiao) commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

#1130 improved InitializeComponent to avoid leading to multiple destructor calls when an exception is thrown, but that patch blocked an important feature: using constructor parameters to initialize XAML elements. I wrote this kind of code back in 2023, when I didn't know about this issue, because the WinUI project template wasn't updated until the end of 2023. Currently, constructor parameters must be saved as members and cannot be naturally passed to InitializeComponent, leads to increased memory usage and performance decrease. This comment also pointed out this issue.

@YexuanXiao

Copy link
Copy Markdown
Contributor Author

Scott Jones (@Scottj1s) Could you review this PR?

Clarified behavior of InitializeComponent with parameters and its impact on XAML runtime callbacks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant